<template>
    <div>
        <h1>康复理疗管理--添加</h1>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">项目名称</td>
                    <td>
                        <input type="text" v-model="queryInfo.name">
                    </td>
                </tr>

                <tr>
                    <td align="right">项目编码</td>
                    <td>
                        <input type="text" v-model="queryInfo.code">
                    </td>
                </tr>

                <tr>
                    <td align="right">佣金（元）</td>
                    <td>
                        <input type="text" v-model="queryInfo.price">
                    </td>
                </tr>

                <tr>
                    <td align="right">服务人数</td>
                    <td>
                        <input type="text" v-model="queryInfo.peopleNum">
                    </td>
                </tr>

                <tr>
                    <td align="right">服务时长</td>
                    <td>
                        <input type="text" v-model="queryInfo.hour">
                    </td>
                </tr>

                <tr>
                    <td align="right">项目说明</td>
                    <td>
                        <textarea v-model="queryInfo.des">

                        </textarea>
                    </td>
                </tr>

                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" name="status" :value="1" v-model="queryInfo.state">启用
                        <input type="radio" name="status" :value="0" v-model="queryInfo.state">禁用
                    </td>
                </tr>

                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="确定" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted} from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import moment from 'moment';
const router = useRouter();
const route = useRoute();

//100-1000

let queryInfo = reactive({
  code: 
  moment(new Date()).format('YYYYMMDD')+
  (parseInt(Math.random()*900)+100), 
  name: '',
  price: '',
  peopleNum: '',
  hour: '',
  des: '',
  state: 1,
})


const ok = () => {
    if(queryInfo.name == ''){
        alert('项目名称不能为空');
        return;
    }
    if(queryInfo.price == ''){
        alert('价格不能为空');
        return;
    }
    if(queryInfo.peopleNum == ''){
        alert('人数不能为空');
        return;
    }
    if(queryInfo.hour == ''){
        alert('时长不能为空');
        return;
    }
    axios({
        url:'/api/KF/Add',
        method: 'post',
        data: queryInfo
    })
    .then(res => {
        console.log(res);
        if(res.data>0){
            alert('添加成功');
            router.push('/kflist');
        }
        else{
            alert('添加失败');
            return;
        }
    })
    .catch(err => {
        console.log(err);
    })
}

</script>

<style scoped>

</style>